package database

import (
	"moft/model"

	"gorm.io/gorm"
)

var db *gorm.DB

func DB() *gorm.DB {
	return db
}

type DatabaseService struct {
	db *gorm.DB
}

func (svc *DatabaseService) Close() error {
	db, err := svc.db.DB()
	if err != nil {
		return err
	}
	return db.Close()
}

func (svc *DatabaseService) MigrateTables() error {
	return svc.db.AutoMigrate(
		model.User{},
		model.Role{},
		model.Client{},
		model.Ticket{},
	)
}
